package comunicacion;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

import sistemaDefensivo.SistemaBateriaMisiles;

public class ServerManager implements Runnable{
	
	private SistemaBateriaMisiles sisBat;
	private Socket socket;
	private ObjectOutputStream writerObject;
	private ObjectInputStream readerObject;
	private DataOutputStream writerData;
	private DataInputStream readerData;
	private int portRespAttk;
	private int coordenadaOrigen;
	
	public ServerManager(Socket socket, SistemaBateriaMisiles sisBat){
		this.sisBat = sisBat;
		this.socket = socket;
	}
	
	@Override
	public void run() {
		try {
			writerObject = new ObjectOutputStream(socket.getOutputStream());
			readerObject = new ObjectInputStream(socket.getInputStream());
			writerData = new DataOutputStream(socket.getOutputStream());
			readerData = new DataInputStream(socket.getInputStream());
//			System.out.println("\nSERVER MANAGER dice =====> Se conecto el cliente: " + socket.getInetAddress());
			portRespAttk = readerData.readInt();

//			System.out.println("Hilo Server Manager dice =====> Puerto de Respuesta Ataque recibido:" + portRespAttk);
			coordenadaOrigen = readerData.readInt();
//			System.out.println("\n!!!!!!!!!!!!!!!!!!!!!!!!SERVER MANAGER dice =====> Se conecto el misil COORDENADA ORIGEN: " + coordenadaOrigen);
		
			socket.close();
			sisBat.lanzarDefensa(socket.getInetAddress().getHostAddress(), portRespAttk, coordenadaOrigen);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
